<template>
    <div>
        <div class="container">
            <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
                <el-tab-pane label="日志管理" name="1">
                    <div class="handle-box" border></div>

                    <el-tabs type="card" @tab-click="handleClick">
                        <el-table border :data="logdata"  v-loading="loading"  element-loading-text="拼命加载中"   element-loading-background="rgb(230 230 230 / 80%)"  element-loading-spinner="el-icon-loading">
                            <el-table-column  label="序号"  width="50">
                                  <template slot-scope="scope">
                                    <span>{{(scope.$index+1)}}</span>
                                </template>
                            </el-table-column>
                              <el-table-column prop="id" label="ID" width="50"></el-table-column>
                            <el-table-column prop="username" label="操作人" width="150"></el-table-column>

                           
                             <el-table-column  label="操作类型"  width="200">
                                  <template slot-scope="scope">
                                     
                                    <span v-if="scope.row.action===3">删除</span>
                                      <span v-if="scope.row.action===2">修改</span>
                                        <span v-if="scope.row.action===1">增加</span>
                                </template> 
                            </el-table-column>
                            <el-table-column prop="create_time" label="操作时间"></el-table-column>

                        </el-table>
                    </el-tabs>

                   
                            
                </el-tab-pane>
              
            </el-tabs>
               <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="params.page"
                    :page-size="params.size"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import fetchData from '../../assets/js/table';

export default {
    name: 'basetable',
    components: {},
    data() {
        return {
            activeName: '1',
            loading:true,
            logdata: [],
            multipleSelection: [],
            delList: [],
            editVisible: false,
            pageTotal: 0,
            form: {},
            idx: -1,

            params: {
               
                page: 1,
                limit: 10,
               
            },
          
        };
    },
    created(option) {
        this.params.parent_id = this.$route.query.id;

        this.getList();
    },
    watch: {
        $route(to, from) {
            if (this.params.parent_id != this.$route.query.id) {
                this.params.parent_id = this.$route.query.id;
                this.getList();
            }
        }
    },
    methods: {
         handlePageChange(val) {
                this.loading=true;
             this.params.page=val;
          
           this.getList();
        },
        sub(){
              let t=this;
          
         

            if(!t.addParams.account){
                return    t.$message.error("请输入用户名");
            }
              if(!t.addParams.password||t.addParams.password<6){
                return    t.$message.error("请输入六位以上得密码");
            }

             t._API.addUser(t.addParams).then(res=>{
            
                        if(res.code===200){
                                 t.$message.success(res.message);
                                t.getList()
                               
                                t.activeName="1";
                        } else {
                                t.$message.error(res.message);
                            
                                return false;
                            }
                    })
        },
        getList() {
            let t = this;
            let d = t.params;
            t._API.getLog(d).then((res) => {
                t.loading=false;
                if (res.code == 200) {
                    t.pageTotal=res.data.total;
                    t.logdata = res.data.lists;
                }
            });
        },
        handleClick(tab, event) {
            console.log(tab, event);
        },
        // // 获取 easy-mock 的模拟数据

        // // 触发搜索按钮
        handleSearch() {
            this.$set(this.params, 'page', 1);
            this.getList();
        },
        // // 删除操作
        handleDelete(index, row) {
            // 二次确认删除
               let t=this;
            this.$confirm('确定要删除吗？', '提示', {
                type: 'warning'
            })
                .then(() => {
                    let d={id:row.id}
                          t._API.deleteUser(d).then(res=>{
            
                        if(res.code===200){
                                t.$message.success(res.message);
                                t.getList()
                               
                            
                        } else {
                                t.$message.error(res.message);
                            
                                return false;
                            }
                     })
                    this.$message.success('删除成功');
                   
                })
                .catch(() => {});
        },
        // // 多选操作
        handleSelectionChange(val) {
            //  this.multipleSelection = val;
        },
        delAllSelection() {
            // const length = this.multipleSelection.length;
            // let str = '';
            // this.delList = this.delList.concat(this.multipleSelection);
            // for (let i = 0; i < length; i++) {
            //     str += this.multipleSelection[i].name + ' ';
            // }
            // this.$message.error(`删除了${str}`);
            // this.multipleSelection = [];
        },
        // // 编辑操作
        // handleEdit(index, row) {
        //     this.idx = index;
        //     this.form = row;
        //     this.editVisible = true;
        // },
        // // 保存编辑
        // saveEdit() {
        //     this.editVisible = false;
        //     this.$message.success(`修改第 ${this.idx + 1} 行成功`);
        //     this.$set(this.tableData, this.idx, this.form);
        // },
        // // 分页导航
      
    }
};
</script>

<style scoped lang="less">
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}

/deep/ .cell {
    font-size: 12px;
}
.adduser{
    padding:0 20px 0 100px;
    >div{
        display: flex;
        align-items: center;
        margin-bottom:20px;
        >div:nth-child(1){
            margin-right: 30px;
            font-size: 14px;
            font-weight: bold;
            width: 70px;
            text-align: right;

        }
        
            /deep/ .el-input__inner{
                border-radius: 0;
                width: 200px;
            }


            .but{
                margin-top: 10px;
            }
    }
}

.mark{
    color:red;
    font-size:14px;
    
    left:93px;
    top:8px;
}
</style>
